TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file Pie.php

Documentation is available at Pie.php

  1. <?php
  2.  
  3. /**
  4.  * Pie class
  5.  *
  6.  * Description: Pie Series
  7.  * Example:
  8.  *  $pieSeries = new Pie($myChart->getChart());
  9.  *  $pieSeries->getMarks()->setVisible(true);
  10.  *  $pieSeries->getShadow()->setVisible(true);
  11.  *  $pieSeries->getShadow()->setHorizSize(20);
  12.  *  $pieSeries->getShadow()->setVertSize(20);
  13.  *  $pieSeries->fillSampleValues(8);
  14.  *
  15.  *  $myChart->getHeader()->setVisible(true);
  16.  *  $myChart->getHeader()->setText("Pie");
  17.  *  $myChart->getAspect()->setElevation(315);
  18.  *  $myChart->getAspect()->setOrthogonal(false);
  19.  *  $myChart->getAspect()->setPerspective(0);
  20.  *  $myChart->getAspect()->setRotation(360);
  21.  *
  22.  * @author
  23.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  24.  * @version 1.0
  25.  * @package TeeChartPHP
  26.  * @subpackage styles
  27.  * @link http://www.steema.com
  28.  */
  29.  
  30.  class Pie extends Circular {
  31.  
  32.     private $OtherFlag;
  33.     private $angleSize = 360;
  34.     private $dark3D = true;
  35.     private $darkPen=null;
  36.     private $explodedSlice=null;
  37.     private $explodeBiggest=0;
  38.     private $otherSlice=null;
  39.     private $shadow=null;
  40.     private $usePatterns=false;
  41.     private $pen=null;
  42.     private $autoMarkPosition = true;
  43.     private $sortedSlice=null;
  44.     private $isExploded=false;
  45.     private $bevelPercent=0;
  46.     private $edgeStyle=2; // EdgeStyles::$NONE
  47.     private $multiPie=0;   // MultiPies::AUTOMATIC
  48.     private $pieMarks=null;
  49.     private $iOldChartRect;
  50.     private $sliceHeight;
  51.  
  52.     protected $iDonutPercent=0;
  53.     protected $iniX;
  54.     protected $iniY;
  55.  
  56.     public $BelongsToOther = -1;
  57.     public $angles=null;
  58.  
  59.     // Interceptors
  60.     function __get( $property ) {
  61.       $method ="get{$property}";
  62.       if ( method_exists( $this, $method ) ) {
  63.         return $this->$method();
  64.       }
  65.     }
  66.  
  67.     function __set ( $property,$value ) {
  68.       $method ="set{$property}";
  69.       if ( method_exists( $this, $method ) ) {
  70.         return $this->$method($value);
  71.       }
  72.     }
  73.  
  74.     /**
  75.     * The class constructor.
  76.     */
  77.     public function Pie($c=null) {
  78.  
  79.         $this->OtherFlag = intval('1000000000000'); // Integer.MAX_VALUE
  80.         $this->explodedSlice = new ExplodedSliceList();
  81.         $this->sliceHeight = new SliceValueList();
  82.  
  83.         parent::Circular($c);
  84.  
  85.         $this->setColorEach(true);
  86.         $tmpColor = new Color(0,0,0);  // Black
  87.         $this->pen = new ChartPen($this->chart, $tmpColor);
  88.         $this->getMarks()->setDefaultVisible(true);
  89.         $this->marks->getArrow()->setDefaultColor($tmpColor);
  90.         $this->marks->getCallout()->setDefaultLength(8);
  91.         $this->useSeriesColor = false;
  92.     }
  93.  
  94.         /**
  95.           * Stores the Pie slice values.
  96.           *
  97.           * @return ValueList 
  98.           */
  99.     public function getPieValues() {
  100.         return $this->vyValues;
  101.     }
  102.  
  103.     public function setChart($c) {
  104.         parent::setChart($c);
  105.         if ($this->pen != null) {
  106.             $this->pen->setChart($this->chart);
  107.         }
  108.         if ($this->shadow != null) {
  109.             $this->shadow->setChart($this->chart);
  110.         }
  111.     }
  112.  
  113.     protected function setDonutPercent($value) {
  114.         $this->iDonutPercent = $this->setIntegerProperty($this->iDonutPercent, $value);
  115.     }
  116.  
  117.         /**
  118.           * Draws points with different preset Colors.<br>
  119.           * Default value: true
  120.           *
  121.           * @return boolean 
  122.           */
  123.     public function getColorEach() {
  124.         return parent::getColorEach();
  125.     }
  126.  
  127.         /**
  128.           * Draws points with different preset Colors.<br>
  129.           * Default value: true
  130.           *
  131.           * @param value boolean
  132.           */
  133.     public function setColorEach($value) {
  134.         parent::setColorEach($value);
  135.     }
  136.  
  137.         /**
  138.           * Total angle in degrees (0 to 360) for all slices.<br>
  139.           * Default value: 360
  140.           *
  141.           * @return int 
  142.           */
  143.     public function getAngleSize() {
  144.         return $this->angleSize;
  145.     }
  146.  
  147.         /**
  148.           * Total angle in degrees (0 to 360) for all slices.<br>
  149.           * Default value: 360<br>
  150.           *
  151.           * <p>Example:
  152.           * <pre><font face="Courier" size="4">
  153.           * pieSeries = new com.steema.teechart.styles.Pie(myChart.getChart());
  154.           * pieSeries.getMarks().setVisible(true);
  155.           * pieSeries.getMarks().setStyle(MarksStyle.LABELPERCENT);
  156.           * pieSeries.fillSampleValues(5);
  157.           * pieSeries.setAngleSize(180);
  158.           * pieSeries.setRotationAngle(90);
  159.           * </font></pre></p>
  160.           *
  161.           * @param value int
  162.           */
  163.     public function setAngleSize($value) {
  164.         $this->angleSize = $this->setIntegerProperty($this->angleSize, $value);
  165.     }
  166.  
  167.         /**
  168.           * Darkens side of 3D pie section to add depth.<br>
  169.           * When true, it fills the Pie 3D effect screen areas with darker colors
  170.           * than their corresponding Pie sectors. These colors look much better
  171.           * with 16k colors video mode or greater. <br>
  172.           * The Pie sector RGB color is increased to 40 units to obtain the darker
  173.           * color. <br>
  174.           * Default value: true
  175.           *
  176.           * @return boolean 
  177.           */
  178.     public function getDark3D() {
  179.         return $this->dark3D;
  180.     }
  181.  
  182.         /**
  183.           * Darkens side of 3D pie section to add depth.<br>
  184.           * Default value: true
  185.           *
  186.           * @param value boolean
  187.           */
  188.     public function setDark3D($value) {
  189.         $this->dark3D = $this->setBooleanProperty($this->dark3D, $value);
  190.     }
  191.  
  192.  
  193.     /**
  194.      * The Transparency level from 0 to 100%.<br>
  195.      * Transparency is a value between 0 and 100 which sets the transparency
  196.      * percentage with respect to foreground versus background.<br>
  197.      * Default value: 0
  198.  
  199.      * @return int 
  200.      */
  201.     public function getTransparency() {
  202.         return $this->getBrush()->getTransparency();
  203.     }
  204.  
  205.     /**
  206.      * Sets Transparency level from 0 to 100%.<br>
  207.      * Default value: 0
  208.      *
  209.      * @param value int
  210.      */
  211.     public function setTransparency($value) {
  212.         $this->getBrush()->setTransparency($value);
  213.     }
  214.  
  215.     /*
  216.     ** Gets and sets the EdgeStyle of the bevel.
  217.     */
  218.     public function getEdgeStyle()
  219.     {
  220.       return $this->edgeStyle;
  221.     }
  222.  
  223.     public function setEdgeStyle($value)
  224.     {
  225.       if ($this->edgeStyle != $value)
  226.       {
  227.         $this->edgeStyle = $value;
  228.         $this->refreshSeries();
  229.       }
  230.     }
  231.  
  232.     /*
  233.     ** Gets and sets the bevel as a percentage of the pie's depth.
  234.     */
  235.     public function getBevelPercent()
  236.     {
  237.       return $this->bevelPercent;
  238.     }
  239.  
  240.     public function setBevelPercent($value)
  241.     {
  242.       if ($this->bevelPercent != $value)
  243.       {
  244.         $this->bevelPercent = $value;
  245.         $this->refreshSeries();
  246.       }
  247.     }
  248.  
  249.         /**
  250.           * Darkens pie slice borders.<br>
  251.           * Default value: false
  252.           *
  253.           * @return boolean 
  254.           */
  255.     public function getDarkPen() {
  256.         return $this->darkPen;
  257.     }
  258.  
  259.         /**
  260.           * Darkens pie slice borders.<br>
  261.           * Default value: false
  262.           *
  263.           * @param value boolean
  264.           */
  265.     public function setDarkPen($value) {
  266.         $this->darkPen = $this->setBooleanProperty($this->darkPen, $value);
  267.     }
  268.  
  269.         /**
  270.           * Displaces the biggest slice from centre by value set.<br>
  271.           * Default value: 0
  272.           *
  273.           * @return int 
  274.           */
  275.     public function getExplodeBiggest() {
  276.         return $this->explodeBiggest;
  277.     }
  278.  
  279.         /**
  280.           * Displaces the biggest slice from centre by value set.<br>
  281.           * Default value: 0
  282.           *
  283.           * @param value int
  284.           */
  285.     public function setExplodeBiggest($value) {
  286.         $this->explodeBiggest = $this->setIntegerProperty($this->explodeBiggest, $value);
  287.         $this->calcExplodeBiggest();
  288.     }
  289.  
  290.         /**
  291.           * Accesses the OtherSlice properties.<br>
  292.           * For example, you can use it to define the grouping size for the
  293.           * 'Other' slice of the Pie.<br>
  294.           * Grouping may be expressed as a percentage or value.<br>
  295.           *
  296.           * <p>Example:
  297.           * <pre><font face="Courier" size="4">
  298.           * pieSeries.getOtherSlice().getLegend().setVisible(isSelected);
  299.           * </font></pre></p>
  300.           *
  301.           * @see com.steema.teechart.styles.Pie.PieOtherSlice#getStyle
  302.           * @return PieOtherSlice 
  303.           */
  304.     public function getOtherSlice() {
  305.         if ($this->otherSlice == null) {
  306.             $this->otherSlice = new PieOtherSlice($this->chart, $this);
  307.         }
  308.         return $this->otherSlice;
  309.     }
  310.  
  311.         /**
  312.           * Line pen for Pie.<br>
  313.           *
  314.           * @return ChartPen 
  315.           */
  316.     public function getPen() {
  317.         return $this->pen;
  318.     }
  319.  
  320.         /**
  321.           * Brush fill for PieSeries.
  322.           *
  323.           * @return ChartBrush 
  324.           */
  325.     public function getBrush() {
  326.         return $this->bBrush;
  327.     }
  328.  
  329.         /**
  330.           * Defines the offset shadow of the PieSeries.
  331.           *
  332.           * <p>Example:
  333.           * <pre><font face="Courier" size="4">
  334.           * pieSeries = new com.steema.teechart.styles.Pie(myChart.getChart());
  335.           * pieSeries.getMarks().setVisible(true);
  336.           * pieSeries.getShadow().setVisible(true);
  337.           * pieSeries.getShadow().setWidth(30);
  338.           * pieSeries.getShadow().setHeight(50);
  339.           * pieSeries.getShadow().setColor(Color.SILVER);
  340.           * pieSeries.fillSampleValues(9);
  341.           *
  342.           * </font></pre></p>
  343.           *
  344.           * @return PieShadow 
  345.           */
  346.     public function getShadow() {
  347.         if ($this->shadow == null) {
  348.             $this->shadow = new PieShadow($this->chart);
  349.         }
  350.         return $this->shadow;
  351.     }
  352.  
  353.         /**
  354.           * Fills Pie Sectors with different Brush pattern styles.<br>
  355.           * Default value: false
  356.           *
  357.           * @return boolean 
  358.           */
  359.     public function getUsePatterns() {
  360.         return $this->usePatterns;
  361.     }
  362.  
  363.         /**
  364.           * Fills Pie Sectors with different Brush pattern styles.<br>
  365.           * Default value: false
  366.           *
  367.           * @param value boolean
  368.           */
  369.     public function setUsePatterns($value) {
  370.         $this->usePatterns = $this->setBooleanProperty($this->usePatterns, $value);
  371.     }
  372.  
  373.         /**
  374.           * If true, marks will be displayed trying to not overlap one to each
  375.           * other.<br>
  376.           * Default value: true
  377.           *
  378.           * @return boolean 
  379.           */
  380.     public function getAutoMarkPosition() {
  381.         return $this->autoMarkPosition;
  382.     }
  383.  
  384.         /**
  385.           * If true, marks will be displayed trying to not overlap one to each
  386.           * other.<br>
  387.           * Default value: true
  388.           *
  389.           * @param value boolean
  390.           */
  391.     public function setAutoMarkPosition($value) {
  392.         $this->autoMarkPosition = $this->setBooleanProperty($this->autoMarkPosition, $value);
  393.     }
  394.  
  395.     private function calcExplodeBiggest() {
  396.         $tmp = $this->getYValues()->indexOf($this->getYValues()->getMaximum());
  397.         if ($tmp != -1) {
  398.             $this->getExplodedSlice()->setSlice($tmp, $this->explodeBiggest);
  399.         }
  400.     }
  401.  
  402.     private function calcExplodedOffset($valueIndex) {
  403.          $offset = new TeePoint();
  404.  
  405.         if ($this->isExploded) {
  406.             $tmpExp = $this->getExplodedSlice()->getSlice($valueIndex);
  407.             if ($tmpExp > 0) {
  408.                 // Apply exploded % to radius
  409.                 $tmp = $this->angles[$valueIndex]->MidAngle;
  410.                 if ($this->chart->getGraphics3D()->getSupportsFullRotation()) {
  411.                     $tmp += (0.25 * 2.0 * M_PI * $this->angleSize / 360.0) +
  412.                             $tmpMath->PI;
  413.                 }
  414.  
  415.                 $tmpSin = sin($tmp + $this->rotDegree);
  416.                 $tmpCos = cos($tmp + $this->rotDegree);
  417.  
  418.                 $tmpExp *= 0.01;
  419.                 $offset->setX(round($this->iXRadius * $tmpExp * $tmpCos));
  420.                 $offset->setY(round($this->iYRadius * $tmpExp * $tmpSin));
  421.             }
  422.         }
  423.  
  424.         return $offset;
  425.     }
  426.  
  427.     public function galleryChanged3D($is3D) {
  428.         parent::galleryChanged3D($is3D);
  429.         $this->disableRotation();
  430.         $this->setCircled((!$this->chart->getAspect()->getView3D()));
  431.     }
  432.  
  433.     private function getAngleSlice($index, $totalAngle) {
  434.         $result = $this->angles[$index]->MidAngle + $this->rotDegree;
  435.         if ($result > $totalAngle) {
  436.             $result -= $totalAngle;
  437.         }
  438.         if ($result > (0.25 * $totalAngle)) {
  439.             $result -= (0.25 * $totalAngle);
  440.  
  441.             if ($result > M_PI) {
  442.                 $result = $totalAngle - $result;
  443.             }
  444.         } else {
  445.             $result = (0.25 * $totalAngle) - $result;
  446.         }
  447.         return $result;
  448.     }
  449.  
  450.     private function disableRotation() {
  451.         $a = $this->chart->getAspect();
  452.         $a->setOrthogonal(false);
  453.         $a->setRotation(0);
  454.         $a->setElevation(305);
  455.     }
  456.  
  457.     protected function swapValueIndex($a, $b) {
  458.         parent::swapValueIndex($a, $b);
  459.         $this->getExplodedSlice()->exchange($a, $b);
  460.     }
  461.  
  462.     protected function addSampleValues($numValues) {
  463.         $pieSampleStr = Array(Language::getString("PieSample1"),
  464.                 Language::getString("PieSample2"),
  465.                 Language::getString("PieSample3"),
  466.                 Language::getString("PieSample4"),
  467.                 Language::getString("PieSample5"),
  468.                 Language::getString("PieSample6"),
  469.                 Language::getString("PieSample7"),
  470.                 Language::getString("PieSample8"));
  471.  
  472.         $r = $this->randomBounds($numValues);
  473.         for ( $t = 0; $t < $numValues; $t++) {
  474.             $this->addYText(/*1+*/round(1000 * $r->Random()), // <-- Value
  475.                 $pieSampleStr[$t % 8]); // <-- Label
  476.         }
  477.     }
  478.  
  479.     private function SliceEndZ($valueIndex)
  480.     {
  481.       if (sizeof($this->sliceHeight) > $valueIndex)
  482.         $result = $this->getStartZ() + round(($this->getEndZ() -
  483.             $this->getStartZ()) * $this->sliceHeight->getSlice($valueIndex) * 0.01);
  484.       else
  485.         $result = $this->getEndZ();
  486.  
  487.       return $result;
  488.     }
  489.  
  490.     private function calcAngles() {
  491.         $totalAngle = 2.0 * M_PI * $this->angleSize / 360.0;
  492.        // todo remove  $tmpSumAbs; //  = $this->getYValues()->getTotalABS();
  493.  
  494.         if ($this->otherSlice->getStyle() == PieOtherStyles::$NONE && $this->firstVisible != -1)
  495.         {
  496.           $tmpSumAbs = 0;
  497.           for ($i = $this->firstVisible; $i <= $this->lastVisible; $i++)
  498.           {
  499.             $tmpSumAbs += abs($this->mandatory->getValue($i));
  500.           }
  501.         }
  502.         else
  503.         {
  504.           $tmpSumAbs = $this->mandatory->getTotalABS();
  505.         }
  506.  
  507.         $piPortion = ($tmpSumAbs != 0) ? $totalAngle / $tmpSumAbs : 0;
  508.  
  509.         // angles.clear();
  510. // TODO check remove -> this was before        $this->angles =new PieAngle[$this->getCount()];
  511.         $this->angles =  Array();
  512.         // TODO remove new PieAngle[$this->getCount()];
  513.  
  514.         $acumValue = 0;
  515.  
  516.         for ( $t = $this->firstVisible; $t <= $this->lastVisible; $t++) {
  517.             $this->angles[$t] = new PieAngle();
  518.             $this->angles[$t]->StartAngle = ($t == $this->firstVisible) ? 0 : $this->angles[$t - 1]->EndAngle;
  519.  
  520.             if ($tmpSumAbs != 0) {
  521.                 if (!$this->belongsToOtherSlice($t)) {
  522.                     $acumValue += abs($this->mandatory->getValue($t));
  523.                 }
  524.                 if ($acumValue == $tmpSumAbs) {
  525.                     $this->angles[$t]->EndAngle = $totalAngle;
  526.                 } else {
  527.                     $this->angles[$t]->EndAngle = $acumValue * $piPortion;
  528.                 }
  529.  
  530.                 /* prevent small pie sectors */
  531.                 if (($this->angles[$t]->EndAngle - $this->angles[$t]->StartAngle) >
  532.                     $totalAngle) {
  533.                     $this->angles[$t]->EndAngle = $this->angles[$t]->StartAngle + $totalAngle;
  534.                 }
  535.             } else {
  536.                 $this->angles[$t]->EndAngle = $totalAngle;
  537.             }
  538.  
  539.             $this->angles[$t]->MidAngle = ($this->angles[$t]->StartAngle + $this->angles[$t]->EndAngle) *
  540.                                  0.5;
  541.         }
  542.     }
  543.  
  544.     protected function calcExplodedRadius($valueIndex) {
  545.         $tmpExp = 1.0 + $this->getExplodedSlice()->getSlice($valueIndex) * 0.01;
  546.         return new TeePoint(round($this->iXRadius * $tmpExp),
  547.                 round($this->iYRadius * $tmpExp));
  548.     }
  549.  
  550.     protected function clearLists() {
  551.         parent::clearLists();
  552.         $this->explodedSlice = new ExplodedSliceList();  // Clears the array
  553.     }
  554.  
  555.     public function doBeforeDrawChart() {
  556.         parent::doBeforeDrawChart();
  557.  
  558.         /* re-order values */
  559.         if ($this->getPieValues()->getOrder() != ValueListOrder::$NONE) {
  560.             $this->getPieValues()->sort();
  561.         }
  562.  
  563.         /* remove "other" slice, if exists...
  564.  
  565.         TODO remove
  566.         for ( $t = 0; $t < $this->getCount(); $t++) {
  567.             if ($this->vxValues->value[$t] == $this->OtherFlag) {
  568.                 $this->delete($t);
  569.                 break;
  570.             }
  571.         }
  572.       */
  573.  
  574.         $this->removeOtherSlice();
  575.  
  576.         $tmpOtherMark= $this->otherMarkCustom();
  577.  
  578.         /* reset X order... */
  579.         $this->getXValues()->fillSequence();
  580.  
  581.         /* calc "Other" slice... */
  582.         if (($this->otherSlice != null) &&
  583.             ($this->otherSlice->getStyle() != PieOtherStyles::$NONE) &&
  584.             ($this->getYValues()->getTotalABS() > 0)) {
  585.             $tmpHasOther = false;
  586.             $tmpValue = 0;
  587.             for ( $t = 0; $t < $this->getCount(); $t++) {
  588.                 $tmp = $this->getYValues()->value[$t];
  589.                 if ($this->otherSlice->getStyle() == PieOtherStyles::$BELOWPERCENT) {
  590.                     $tmp = $tmp * 100.0 / $this->getYValues()->getTotalABS();
  591.                 }
  592.                 if ($tmp < $this->otherSlice->getValue()) {
  593.                     $tmpValue += $this->getYValues()->value[$t];
  594.                     $this->getXValues()->value[$t] = $this->BelongsToOther;
  595.                     /* <-- belongs to "other" */
  596.                     $tmpHasOther = true;
  597.                 }
  598.             }
  599.  
  600.             // Add "Other" slice
  601.             if ($tmpHasOther) {
  602.                 // 5.02
  603.                 $t= $this->add($this->OtherFlag, $tmpValue, $this->otherSlice->text, $this->otherSlice->getColor());
  604.  
  605.                 $this->getYValues()->totalABS -= $tmpValue; /*   $total */
  606.                 $this->getYValues()->statsOk = true;
  607.  
  608.                 if ($tmpOtherMark != null)
  609.                 {
  610.                   $this->getMarks()->getPositions()->setPosition($t,$tmpOtherMark);
  611.                 }
  612.             }
  613.         }
  614.     }
  615.  
  616.     // Returns index of "this" into all visible Pie series
  617.     private function pieIndex()
  618.     {
  619.       $result = 0;
  620.  
  621.       for ($i=0; $i<$this->getChart()->getSeriesCount();$i++)
  622.       {
  623.         if ($this->chart->getSeries($i) === $this)
  624.           break;
  625.         else
  626.           if ($this->chart->getSeries($i)->getActive() && $this->sameClass($this->chart->getSeries($i)))
  627.             $result++;
  628.       }
  629.  
  630.       return $result;
  631.     }
  632.  
  633.     // Returns number of visible Pie series
  634.     private function pieCount()
  635.     {
  636.       $result = 0;
  637.       for ($i=0; $i<$this->chart->getSeriesCount();$i++)
  638.       {
  639.         if (($this->chart->getSeries($i)->getActive()) && ($this->sameClass($this->chart->getSeries($i))))
  640.           $result++;
  641.       }
  642.  
  643.       return $result;
  644.     }
  645.  
  646.     private function guessRectangle()
  647.     {
  648.       $tmpCount = $this->pieCount();
  649.  
  650.       if ($tmpCount > 1)
  651.       {
  652.         $tmpIndex = $this->pieIndex();
  653.  
  654.         $tmpR = $this->chart->getChartRect();
  655.         $tmpW = $tmpR->getWidth();
  656.         $tmpH = $tmpR->getHeight();
  657.         $tmpCols = round(sqrt($tmpCount));
  658.  
  659.         $tmpR->setX($tmpR->getX() + ($tmpIndex % $tmpCols) * ($tmpW / $tmpCols));
  660.         $tmpR->setWidth(($tmpW / $tmpCols));
  661.  
  662.         $tmpRows = round(0.5 + sqrt($tmpCount));
  663.  
  664.         $tmpR->setY($tmpR->getY() + (($tmpIndex / $tmpCols)) * ($tmpH / $tmpRows));
  665.         $tmpR->setHeight(($tmpH / $tmpRows));
  666.  
  667.         $this->chart->setChartRect($this->chart->getGraphics3D()->calcRect3D($tmpR, 0));
  668.       }
  669.     }
  670.  
  671.     // Calculate "this" Pie rectangle, when multiple pie series exist.
  672.     protected function DoBeforeDrawValues()
  673.     {
  674.       $this->iOldChartRect = $this->chart->getChartRect();
  675.  
  676.       if ($this->multiPie == MultiPies::$AUTOMATIC)
  677.         $this->guessRectangle();
  678.  
  679.       parent::doBeforeDrawValues();
  680.     }
  681.  
  682.     // Resets back old chart rectangle
  683.     protected function DoAfterDrawValues()
  684.     {
  685.       $this->chart->setChartRect($this->iOldChartRect);
  686.       parent::doAfterDrawValues();
  687.     }
  688.  
  689.     private function removeOtherSlice()
  690.         {
  691.             /* remove "other" slice, if exists... */
  692.             for ($t = 0; $t < $this->getCount(); $t++)
  693.                 if ($this->vxValues->getValue($t) == $this->OtherFlag)
  694.                 {
  695.                     $this->delete($t);
  696.                     break;
  697.                 }
  698.         }
  699.  
  700.     private function otherMarkCustom()
  701.         {
  702.             for ($i = 0; $i < $this->getCount(); $i++)
  703.             {
  704.                 if ($this->vxValues->getValue($i) == $this->OtherFlag)
  705.                 {
  706.                     $tmp = $this->getMarks()->getPositions()->getPosition($i);
  707.  
  708.                     if ($tmp != null && $tmp->custom)
  709.                     {
  710.                         $result = new SeriesMarksPosition();
  711.                         $tmp->assign($result);
  712.  
  713.             return $result;
  714.                     }
  715.                     break;
  716.                 }
  717.             }
  718.  
  719.             return null;
  720.         }
  721.  
  722.     protected function draw() {
  723.  
  724.         if ($this->explodeBiggest > 0) {
  725.             $this->calcExplodeBiggest();
  726.         }
  727.  
  728.         $maxExplodedIndex = -1;
  729.         $maxExploded = 0;
  730.         $tmpCount = $this->getCount();
  731.  
  732.         // calc biggest exploded index
  733.         for ( $t = 0; $t < sizeof($this->getExplodedSlice()); $t++) {
  734.             if ($this->getExplodedSlice()->getSlice($t) > $maxExploded) {
  735.                 $maxExploded = round($this->getExplodedSlice()->getSlice($t));
  736.                 $maxExplodedIndex = $t;
  737.             }
  738.         }
  739.  
  740.         // calc each slice angles
  741.         $this->calcAngles();
  742.  
  743.         //adjust circle rectangle
  744.         $this->isExploded = ($maxExplodedIndex != -1);
  745.         if ($this->isExploded) {
  746.             $tmpOff = $this->calcExplodedOffset($maxExplodedIndex);
  747.  
  748.             $this->getCircleRect()->grow( -abs($tmpOff->getX()) / 2,
  749.                                     -abs($tmpOff->getY()) / 2);
  750.  
  751.             //InflateRect(circleRect,-Math.abs(tmpOffX) /2 ,-Math.abs(tmpOffY) / 2);
  752.  
  753.             $this->adjustCircleRect();
  754.             $this->calcRadius();
  755.         }
  756.  
  757.         /* start xy pos */
  758.         $ini = $this->angleToPos(0, $this->iXRadius, $this->iYRadius);
  759.  
  760.         $g = $this->chart->getGraphics3D();
  761.  
  762.         /* TODO
  763.         if (($this->shadow != null) && ($this->shadow->getVisible()) &&
  764.             (!$this->shadow->getColor()->isEmpty()) &&
  765.             (($this->shadow->getWidth() != 0) || ($this->shadow->getHeight() != 0))) {
  766.             $g->setBrush($this->shadow->getBrush());
  767.             $g->getPen()->setVisible(false);
  768.              $r = $this->rCircleRect;
  769.             $r->offset($this->shadow->getWidth(), $this->shadow->getHeight());
  770.             $g->ellipse($r, $this->getEndZ() - 10);
  771.         } */
  772.  
  773.         //CDI PieOtherSlice Legend
  774.         $rect = $this->chart->getChartRect();
  775.  
  776.         if ($this->getOtherSlice()->getLegend() != null &&
  777.             $this->getOtherSlice()->getLegend()->getVisible()) {
  778.             $tmp = $this->chart->getLegend();
  779.             $this->chart->setLegend($this->getOtherSlice()->getLegend());
  780.             $rect = $this->chart->doDrawLegend($g, $rect);
  781.             $this->chart->setLegend($tmp);
  782.         }
  783.  
  784.         if ($this->shouldDrawShadow())
  785.         {                      // TODO review rect params
  786.           $this->shadow->draw($g, new Rectangle($this->iCircleXCenter - $this->iXRadius,
  787.                                        ($this->iCircleYCenter - $this->iYRadius) + ($this->endZ - $this->startZ),
  788.                                        $this->iCircleXCenter + $this->iXRadius,
  789.                                        ($this->iCircleYCenter + $this->iYRadius) + ($this->endZ - $this->startZ)),0,
  790.                                        $this->endZ - $this->startZ);
  791.         }
  792.  
  793.         /* exploded slices drawing order... */
  794.         if ($this->chart->getAspect()->getView3D() && ($this->isExploded || ($this->iDonutPercent > 0))
  795.             && (!$g->getSupportsFullRotation())) {
  796.             if ($this->sortedSlice == null) {
  797.                 $this->sortedSlice = Array(); // TODO remove int[$tmpCount];
  798.             }
  799.  
  800.             for ( $t = 0; $t < $tmpCount; $t++) {
  801.                 $this->sortedSlice[$t] = $t;
  802.             }
  803.  
  804.             Utils::sort($this->sortedSlice, 0, $tmpCount-1, new CompareSlice());
  805.  
  806.             for ( $t = 0; $t < $tmpCount; $t++) {
  807.                 $this->drawValue($this->sortedSlice[$t]);
  808.             }
  809.         } else {
  810.             parent::draw();
  811.         }
  812.  
  813.         if ($this->getOtherSlice()->getLegend() != null &&
  814.             $this->getOtherSlice()->getLegend()->getVisible()) {
  815.             $tmp = $this->chart->getLegend();
  816.             $this->chart->setLegend($this->getOtherSlice()->getLegend());
  817.             $rect = $this->chart->doDrawLegend($g, $rect);
  818.             $this->chart->setLegend($tmp);
  819.         }
  820.     }
  821.  
  822.     private function shouldDrawShadow()
  823.     {
  824.       return ($this->shadow != null) && ($this->shadow->bVisible) &&
  825.         (!Utils::colorIsEmpty($this->shadow->getColor())) && (($this->shadow->getWidth() != 0) ||
  826.         ($this->shadow->getHeight() != 0));
  827.     }
  828.  
  829.     /*protected boolean drawMarksSeries(Series s, boolean activeRegion)
  830.     {
  831.       //OpenGL only
  832.       IGraphics3D g = chart.getGraphics3D();
  833.       g.elevate(90);
  834.       return super.drawMarksSeries(s, activeRegion);
  835.     }*/
  836.  
  837.     protected function drawMark($valueIndex, $s, $position) {
  838.  
  839.         if (!$this->belongsToOtherSlice($valueIndex)) {
  840.  
  841.              $tmpRadius = $this->calcExplodedRadius($valueIndex);
  842.  
  843. //            if ($this->chart->getGraphics3D()->getSupportsFullRotation()) {
  844. //                $tmp = $this->angles[$valueIndex]->MidAngle + M_PI + 0.5 * M_PI;
  845. //                $this->getMarks()->setZPosition($this->getStartZ());
  846. //            } else {
  847. //                $tmp = $this->angles[$valueIndex]->MidAngle;
  848. //                $this->getMarks()->setZPosition($this->getEndZ());
  849. //            }
  850.  
  851.              $tmp = $this->angles[$valueIndex]->MidAngle;
  852.              $this->getMarks()->setZPosition($this->SliceEndZ($valueIndex));
  853.  
  854.              $position->arrowFix = true;
  855.              $tmpLength = $this->getMarks()->getCallout()->getLength() +
  856.                             $this->getMarks()->getCallout()->getDistance();
  857.              $tmpXY = $this->angleToPos($tmp,
  858.                                      $tmpRadius->x
  859.                                      /*+Drawing.TextWidth(TeeCharForHeight)*/
  860.                                      +
  861.                                      $tmpLength,
  862.                                      $tmpRadius->y
  863.                                      /*+Drawing.FontHeight*/+ $tmpLength
  864.                           );
  865.  
  866.             $position->arrowTo = $tmpXY;
  867.  
  868.             $tmpLength = $this->getMarks()->getCallout()->getDistance();
  869.             $tmpXY = $this->angleToPos($tmp, $tmpRadius->x + $tmpLength,
  870.                                $tmpRadius->y + $tmpLength);
  871.             $position->arrowFrom = $tmpXY;
  872.  
  873.             if ($position->arrowTo->x > $this->iCircleXCenter) {
  874.                 $position->leftTop->x = $position->arrowTo->x;
  875.             } else {
  876.                 $position->leftTop->x = $position->arrowTo->x - $position->width;
  877.             }
  878.  
  879.             if ($position->arrowTo->y > $this->iCircleYCenter) {
  880.                 $position->leftTop->y = $position->arrowTo->y;
  881.             } else {
  882.                 $position->leftTop->y = $position->arrowTo->y - $position->height;
  883.             }
  884.  
  885.             if ($this->getMarksPie()->getVertCenter())
  886.             {
  887.               $tmpypos = $position->height / 2;
  888.               if ($position->arrowTo->y > $this->iCircleYCenter) $position->arrowTo->y += $tmpypos;
  889.               else $position->arrowTo->y -= $tmpypos;
  890.             }
  891.  
  892.             if ($this->getMarksPie()->getLegSize() == 0)
  893.             {
  894.             /* TODO
  895.               $position->hasMid = false;
  896.               $position->midPoint->x = 0;
  897.               $position->midPoint->y = 0;
  898.               */
  899.             }
  900.             else
  901.             {
  902.               $position->hasMid = true;
  903.               if ($position->arrowTo->x > $this->iCircleXCenter)
  904.               {
  905.                 if (($position->arrowTo->x - $this->getMarksPie()->getLegSize()) < $position->arrowFrom->x)
  906.                 {
  907.                   $position->midPoint->x = $position->arrowFrom->x;
  908.                   $position->arrowTo->x = $position->arrowTo->x + $this->getMarksPie()->getLegSize();
  909.                   $position->leftTop->x = $position->arrowTo->x;
  910.                 }
  911.                 else
  912.                   $position->midPoint->x = $position->arrowTo->x - $this->getMarksPie()->getLegSize();
  913.               }
  914.               else
  915.               {
  916.                 if (($position->arrowTo->x + $this->getMarksPie()->getLegSize()) > $position->arrowFrom->x)
  917.                 {
  918.                   $position->midPoint->x = $position->arrowFrom->x;
  919.                   $position->arrowTo->x = $position->arrowFrom->x - $this->getMarksPie()->getLegSize();
  920.                   $position->leftTop->x = $position->arrowTo->x - $position->width;
  921.                 }
  922.                 else
  923.                   $position->midPoint->x = $position->arrowTo->x + $this->getMarksPie()->getLegSize();
  924.               }
  925.               $position->midPoint->y = $position->arrowTo->y;
  926.             }
  927.  
  928.             if ($this->getAutoMarkPosition()) {
  929.                 $this->getMarks()->antiOverlap($this->firstVisible, $valueIndex, $position);
  930.             }
  931.  
  932.             parent::drawMark($valueIndex, $s, $position);
  933.         }
  934.     }
  935.  
  936.     public function getMarksPie()
  937.     {
  938.         if ($this->pieMarks == null) {
  939.           $this->pieMarks = new PieMarks($this->chart, $this);
  940.         }
  941.  
  942.         return $this->pieMarks;
  943.     }
  944.  
  945.     public function setMarksPie($value)
  946.     {
  947.         $this->pieMarks = $value;
  948.     }
  949.  
  950.     public function drawOutlineSlice($valueIndex) {
  951.         //TJ71012746 pending checks at
  952.         //Graphics finishSide(endAngle, z0);
  953.         $tmpOff = $this->calcExplodedOffset($valueIndex);
  954.  
  955.         $g = $this->chart->getGraphics3D();
  956.  
  957.         if (($this->chart->getAspect()->getView3D()) || ($this->iDonutPercent == 0)) {
  958.             $g->pie($this->iCircleXCenter + $tmpOff->getX(),
  959.                   $this->iCircleYCenter - $tmpOff->getY(), 0,0,
  960.                   $this->iXRadius, $this->iYRadius, $this->getStartZ(), $this->SliceEndZ($valueIndex),
  961.                   $this->angles[$valueIndex]->StartAngle + $this->rotDegree,
  962.                   $this->angles[$valueIndex]->EndAngle + $this->rotDegree,
  963.                   $this->dark3D,
  964.                   false,
  965.                   $this->iDonutPercent, $this->bevelPercent, $this->edgeStyle, false);
  966.         } else {
  967.             //if ( donutPercent>0 )
  968.             $g->donut($this->iCircleXCenter + $tmpOff->getX(), $this->iCircleYCenter - $tmpOff->getY(),
  969.                     $this->iXRadius, $this->iYRadius,
  970.                     $this->angles[$valueIndex]->StartAngle + $this->rotDegree,
  971.                     $this->angles[$valueIndex]->EndAngle + $this->rotDegree,
  972.                     $this->iDonutPercent);
  973.         }
  974.     }
  975.  
  976. /* TODO remove
  977.  
  978.     public function drawPie($valueIndex) {
  979.          $tmpOff = $this->calcExplodedOffset($valueIndex);
  980.  
  981.          $g = $this->chart->getGraphics3D();
  982.  
  983.         if (($this->chart->getAspect()->getView3D()) || ($this->iDonutPercent == 0)) {
  984.             $g->pie($this->iCircleXCenter + $tmpOff->getX(),
  985.                   $this->iCircleYCenter - $tmpOff->getY(),
  986.                   $this->iXRadius, $this->iYRadius, $this->getStartZ(), $this->getEndZ(),
  987.                   $this->angles[$valueIndex]->StartAngle + $this->rotDegree,
  988.                   $this->angles[$valueIndex]->EndAngle + $this->rotDegree,
  989.                   $this->dark3D,
  990.                   $this->isExploded,
  991.                   $this->iDonutPercent);
  992.         } else {
  993.             //if ( donutPercent>0 )
  994.             $g->donut($this->iCircleXCenter + $tmpOff->getX(), $this->iCircleYCenter - $tmpOff->getY(),
  995.                     $this->iXRadius, $this->iYRadius,
  996.                     $this->angles[$valueIndex]->StartAngle + $this->rotDegree,
  997.                     $this->angles[$valueIndex]->EndAngle + $this->rotDegree,
  998.                     $this->iDonutPercent);
  999. //        else
  1000. //        {
  1001. //          g.Pie( circleXCenter+tmpOffX,
  1002. //            circleYCenter-tmpOffY,
  1003. //            xRadius,yRadius, getStartZ(), getEndZ(),
  1004. //            Angles[valueIndex].StartAngle+rotDegree,
  1005. //            Angles[valueIndex].EndAngle+rotDegree,
  1006. //            dark3D,
  1007. //            IsExploded,
  1008. //            donutPercent);
  1009.  
  1010. //          AngleToPos(Angles[valueIndex].EndAngle,xRadius,yRadius,out EndX,out EndY);
  1011. //          if ( ((IniX!=EndX) || (IniY!=EndY)) || (Count==1) ||
  1012. //            ( (Count>1) && (Angles[valueIndex].EndAngle-Angles[ValueIndex].StartAngle>1) )  )
  1013. //          { /* bug win32 api */
  1014. //
  1015. //            Rectangle r=circleRect;
  1016. //
  1017. //            g.Pie(r.x+tmpOffX,r.y-tmpOffY,r.Right()+tmpOffX,r.Bottom()-tmpOffY,
  1018. //              180*Angles[valueIndex].StartAngle/Math.PI,
  1019. //              180*Angles[valueIndex].EndAngle/Math.PI);
  1020. //            //                        g.Pie(r.x+tmpOffX,r.y-tmpOffY,r.Right+tmpOffX,r.Bottom-tmpOffY,
  1021. //            //                            IniX+tmpOffX,IniY-tmpOffY,EndX+tmpOffX,EndY-tmpOffY);
  1022. //            IniX=EndX;
  1023. //            IniY=EndY;
  1024. //          }
  1025. //         }
  1026. /*        }
  1027.     }
  1028. */
  1029.     public function drawPie($valueIndex,$last) {
  1030.  
  1031.         $tmpOff = $this->calcExplodedOffset($valueIndex);
  1032.  
  1033.         $g = $this->chart->getGraphics3D();
  1034. //
  1035. //        if ((chart.getAspect().getView3D()) || (iDonutPercent == 0)) {
  1036. //            g.pie(iCircleXCenter + tmpOff.x,
  1037. //                  iCircleYCenter - tmpOff.y,
  1038. //                  iXRadius, iYRadius, getStartZ(), SliceEndZ(valueIndex),
  1039. //                  angles[valueIndex].StartAngle + rotDegree,
  1040. //                  angles[valueIndex].EndAngle + rotDegree,
  1041. //                  dark3D,
  1042. //                  isExploded,
  1043. //                  iDonutPercent);
  1044. //        } else {
  1045. //            //if ( donutPercent>0 )
  1046. //            g.donut(iCircleXCenter + tmpOff.x, iCircleYCenter - tmpOff.y,
  1047. //                    iXRadius, iYRadius,
  1048. //                    angles[valueIndex].StartAngle + rotDegree,
  1049. //                    angles[valueIndex].EndAngle + rotDegree,
  1050. //                    iDonutPercent);
  1051. //
  1052. //        }
  1053.  
  1054. //      int tmpOffX;
  1055. //            int tmpOffY;
  1056. //            CalcExplodedOffset(valueIndex, out tmpOffX, out tmpOffY);
  1057. //
  1058.             if ($this->angleSize < 360)
  1059.             {
  1060.                 $this->isExploded = true;
  1061.             }
  1062.  
  1063.             $g->pie($this->iCircleXCenter,
  1064.                     $this->iCircleYCenter, $tmpOff->getX(), $tmpOff->getY(),
  1065.                     $this->iXRadius, $this->iYRadius, $this->startZ, $this->SliceEndZ($valueIndex),
  1066.                     $this->angles[$valueIndex]->StartAngle + $this->rotDegree,
  1067.                     $this->angles[$valueIndex]->EndAngle + $this->rotDegree,
  1068.                     $this->dark3D,
  1069.                     $this->isExploded,
  1070.                     $this->iDonutPercent, $this->bevelPercent, $this->edgeStyle,$last);
  1071.     }
  1072.  
  1073.         /**
  1074.           * Called internally. Draws the "ValueIndex" point of the Series.
  1075.           *
  1076.           * @param valueIndex int
  1077.           */
  1078.     public function drawValue($valueIndex) {
  1079.         if (($this->getCircleWidth() > 4) && ($this->getCircleHeight() > 4)) {
  1080.             if (!$this->belongsToOtherSlice($valueIndex)) {
  1081.                 // Slice pattern
  1082.                 if ($this->usePatterns || $this->chart->getGraphics3D()->getMonochrome()) {
  1083.                     $this->bBrush->setStyle(GraphicsGD::getDefaultPattern($valueIndex));
  1084.                 } else {
  1085.                     $this->bBrush->setSolid(true);
  1086.                 }
  1087.  
  1088.                  $tmpColor = $this->chart->getGraphics3D()->getMonochrome() ?
  1089.                                  new Color(0,0,0) :
  1090.                                  $this->getValueColor($valueIndex);
  1091.  
  1092.                 // Set slice back color
  1093.                 $this->chart->setBrushCanvas($tmpColor, $this->bBrush, $this->calcCircleBackColor());
  1094.                 $this->preparePiePen($this->chart->getGraphics3D(), $valueIndex);
  1095.                 $this->drawPie($valueIndex, $valueIndex==$this->getCount()-1);
  1096.             }
  1097.         }
  1098.     }
  1099.  
  1100.     protected function numSampleValues() {
  1101.         return 8;
  1102.     }
  1103.  
  1104.     public function prepareForGallery($isEnabled) {
  1105.         parent::prepareForGallery($isEnabled);
  1106.         $this->fillSampleValues(8);
  1107.         $this->chart->getAspect()->setChart3DPercent(75);
  1108.         $this->getMarks()->getCallout()->setLength(0);
  1109.         $this->getMarks()->setDrawEvery(1);
  1110.         $this->disableRotation();
  1111.         $this->setColorEach($isEnabled);
  1112.     }
  1113.  
  1114.         //CDI PieOtherSlice.Legend
  1115.     public function legendToValueIndex($legendIndex) {
  1116.          $num = -1;
  1117.  
  1118.          $tmpIsOther = $this->chart->getLegend() != null &&
  1119.                      $this->chart->getLegend() == $this->getOtherSlice()->getLegend();
  1120.  
  1121.         for ( $t = 0; $t < $this->getCount(); $t++) {
  1122.              $tmp = $this->belongsToOtherSlice($t);
  1123.             if (($tmpIsOther && $tmp) || ((!$tmpIsOther) && (!$tmp))) {
  1124.                 $num++;
  1125.                 if ($num == $legendIndex) {
  1126.                     return $t;
  1127.                 }
  1128.             }
  1129.         }
  1130.         return $legendIndex;
  1131.     }
  1132.  
  1133.     private function preparePiePen($g, $valueIndex) {
  1134.         $g->setPen($this->pen);
  1135.         if ($this->darkPen) {
  1136.             $tmpGraphics3D = new Graphics3D();
  1137.             $g->getPen()->setColor(GraphicsGD::applyDark($this->getValueColor($valueIndex),
  1138.                     $tmpGraphics3D->DARKERCOLORQUANTITY));
  1139.         }
  1140.     }
  1141.  
  1142.     protected function prepareLegendCanvas($g, $valueIndex, $backColor, $aBrush) {
  1143.  
  1144.         parent::prepareLegendCanvas($g, $valueIndex, $backColor, $aBrush);
  1145.         $this->preparePiePen($g, $valueIndex);
  1146.  
  1147.         // Slice pattern
  1148.         if ($this->usePatterns || $g->getMonochrome()) {
  1149.             $aBrush->setStyle(GraphicsGD::getDefaultPattern($valueIndex));
  1150.         } else {
  1151.             $aBrush->setSolid(true);
  1152.         }
  1153.     }
  1154.  
  1155.         /**
  1156.           * Returns true if indexed Slice belongs to the Otherslice.<br>
  1157.           * The "other" slice is controlled by the OtherSlice method, and is used
  1158.           * to join several small slices into a single bigger one.
  1159.           *
  1160.           * @param valueIndex int
  1161.           * @return boolean 
  1162.           */
  1163.     public function belongsToOtherSlice($valueIndex) {
  1164.         return $this->vxValues->value[$valueIndex] == $this->BelongsToOther;
  1165.     }
  1166.  
  1167.         /**
  1168.           * Returns the pixel Screen Horizontal coordinate of the ValueIndex Series value.
  1169.           *
  1170.           * @param valueIndex int
  1171.           * @return int 
  1172.           */
  1173.     public function calcXPos($valueIndex) {
  1174.         if ($this->vxValues->value[$valueIndex] == $this->OtherFlag) {
  1175.             return 0;
  1176.         } else {
  1177.             return parent::calcXPos($valueIndex);
  1178.         }
  1179.     }
  1180.  
  1181.     public function clicked($x, $y) {
  1182.         $tmpResult = parent::clicked($x, $y);
  1183.         if ($tmpResult == -1) {
  1184.             $tmpResult = $this->calcClickedPie($x, $y);
  1185.         }
  1186.         return $tmpResult;
  1187.     }
  1188.  
  1189.     private function calcClickedPie($x, $y) {
  1190.         if ($this->chart != null) {
  1191.              $p = $this->chart->getGraphics3D()->calculate2DPosition($x, $y,
  1192.                     $this->chart->getAspect()->getWidth3D());
  1193.  
  1194.             $x = $p->x;
  1195.             $y = $p->y;
  1196.         }
  1197.  
  1198.         $tmpAngle = $this->pointToAngle($x, $y);
  1199.  
  1200.         for ( $result = 0; $result < $this->getCount(); $result++) {
  1201.              $tmpOff = $this->calcExplodedOffset($result);
  1202.  
  1203.             if ((abs($x - $this->getCircleXCenter()) <= ($this->getXRadius() + $tmpOff->x)) &&
  1204.                 (abs($y - $this->getCircleYCenter()) <= ($this->getYRadius() + $tmpOff->y))) {
  1205.                 if ($this->angles[$result]->contains($tmpAngle)) {
  1206.                     return $result;
  1207.                 }
  1208.             }
  1209.         }
  1210.         return -1;
  1211.     }
  1212.  
  1213.     public function getCountLegendItems() {
  1214.          $result = 0;
  1215.         for ( $t = 0; $t < $this->getCount(); $t++) {
  1216.             if ($this->belongsToOtherSlice($t)) {
  1217.                 $result++;
  1218.             }
  1219.         }
  1220.  
  1221.         //if(chart.ILegend!=null && chart.ILegend == OtherSlice.Legend) {
  1222.         if ($this->chart->getLegend() != null &&
  1223.             $this->chart->getLegend() == $this->getOtherSlice()->getLegend()) {
  1224.             return $result;
  1225.         } else {
  1226.             return $this->getCount() - $result;
  1227.         }
  1228.     }
  1229.  
  1230.     public function createSubGallery($addSubChart) {
  1231.         parent::createSubGallery($addSubChart);
  1232.         $addSubChart->createSubChart($this->Language->getString("Patterns"));
  1233.         $addSubChart->createSubChart($this->Language->getString("Exploded"));
  1234.         $addSubChart->createSubChart($this->Language->getString("Shadow"));
  1235.         $addSubChart->createSubChart($this->Language->getString("Marks"));
  1236.         $addSubChart->createSubChart($this->Language->getString("SemiPie"));
  1237.         $addSubChart->createSubChart($this->Language->getString("NoBorder"));
  1238.         $addSubChart->createSubChart($this->Language->getString("DarkPen"));
  1239.     }
  1240.  
  1241.     public function setSubGallery($index) {
  1242.         switch ($index) {
  1243.         case 1:
  1244.             $this->setUsePatterns(true);
  1245.             break;
  1246.         case 2:
  1247.             $this->setExplodeBiggest(30);
  1248.             break;
  1249.         case 3: {
  1250.             $this->getShadow()->setVisible(true);
  1251.             $this->getShadow()->setWidth(10);
  1252.             $this->getShadow()->setHeight(10);
  1253.         }
  1254.         break;
  1255.         case 4: {
  1256.             $this->getMarks()->setVisible(true);
  1257.             $this->clear();
  1258.             $this->add(30, "A");
  1259.             $this->add(70, "B");
  1260.         }
  1261.         break;
  1262.         case 5:
  1263.             $this->setAngleSize(180);
  1264.             break;
  1265.         case 6:
  1266.             $this->getPen()->setVisible(false);
  1267.             break;
  1268.         case 7:
  1269.             $this->setDarkPen(true);
  1270.             break;
  1271.         default: break;
  1272.         }
  1273.     }
  1274.  
  1275.     /**
  1276.      * Accesses the properties for exploding any Pie slice.
  1277.      *
  1278.      * @return ExplodedSliceList 
  1279.      */
  1280.     public function getExplodedSlice() {
  1281.       if ($this->explodedSlice==null)
  1282.       {
  1283.          $this->explodedSlice = new ExplodedSliceList();
  1284.       }
  1285.  
  1286.       return $this->explodedSlice;
  1287.     }
  1288.  
  1289.     /**
  1290.      * Gets descriptive text.
  1291.      *
  1292.      * @return String 
  1293.      */
  1294.     public function getDescription() {
  1295.         return $this->Language->getString("GalleryPie");
  1296.     }
  1297. }
  1298.  
  1299.      /**
  1300.      *
  1301.      * <p>Title: PieOtherSlice class</p>
  1302.      *
  1303.      * <p>Description: Pie series uses this class in its Pie.OtherSlice.</p>
  1304.      *
  1305.      * <p>Copyright (c) 2005-2008 by Steema Software SL. All Rights Reserved.</p>
  1306.      *
  1307.      * <p>Company: Steema Software SL</p>
  1308.      *
  1309.      * @see Pie#getOtherSlice
  1310.      */
  1311.      class PieOtherSlice extends TeeBase {
  1312.  
  1313.         private $color;
  1314.         private $text;
  1315.         private $aValue;
  1316.         private $legend;
  1317.         private $series;
  1318.         private $style;
  1319.  
  1320.  
  1321.         public function PieOtherSlice($c, $s) {
  1322.             $this->style = PieOtherStyles::$NONE;
  1323.  
  1324.             parent::__construct($c);
  1325.             $this->text = "Other";
  1326.             $tmpColor = new Color(0,0,0,0,true);  // EMPTY black
  1327.             $this->color = $tmpColor;
  1328.             if ($this->series == null) {
  1329.                 $this->series = $s;
  1330.             }
  1331.         }
  1332.  
  1333.         /**
  1334.         * The Color of the OtherSlice.
  1335.         *
  1336.         * @return Color 
  1337.         */
  1338.         public function getColor() {
  1339.             return $this->color;
  1340.         }
  1341.  
  1342.         /**
  1343.         * Sets the Color of the OtherSlice.
  1344.         *
  1345.         * @param value Color
  1346.         */
  1347.         public function setColor($value) {
  1348.             $this->color = $this->setColorProperty($this->color, $value);
  1349.         }
  1350.  
  1351.         private function setLegend($value) {
  1352.             if ($this->legend != null) {
  1353.                 $this->legend = $value;
  1354.                 $this->legend->setSeries($this->series);
  1355.             }
  1356.         }
  1357.  
  1358.                 /**
  1359.                   * Sets the properties of the PieOtherSlice Legend.<br><br>
  1360.                   *
  1361.                   * Example This sample shows how to use PieOtherSlice Legend:<br><br>
  1362.                   *
  1363.                   * prepare "Other" to group values below 10<br>
  1364.                   * pie1.getOtherSlice().setStyle(PieOtherStyles.BELOWVALUE);<br>
  1365.                   * pie1.getOtherSlice().setValue(10);<br>
  1366.                   * pie1.getOtherSlice().setText("Other");<br>
  1367.                   * pie1.getOtherSlice().getLegend().setVisible( true );<br>
  1368.                   * pie1.getOtherSlice().getLegend().setCustomPosition( true );<br>
  1369.                   * pie1.getOtherSlice().getLegend().setLeft( 350 );<br>
  1370.                   * pie1.getOtherSlice().getLegend().setTop( 150 );<br>
  1371.                   *
  1372.                   *
  1373.                   * @return Legend 
  1374.                   */
  1375.         public function getLegend() {
  1376.             if ($this->legend == null) {
  1377.                 $this->legend = new Legend($this->series->getChart());
  1378.                 $this->legend->setVisible(false);
  1379.                 $this->legend->setSeries($this->series);
  1380.             }
  1381.             return $this->legend;
  1382.         }
  1383.  
  1384.         /**
  1385.         * Title for otherSlice.<br>
  1386.         * Default value: Other
  1387.         *
  1388.         * @return String 
  1389.         */
  1390.         public function getText() {
  1391.             return $this->text;
  1392.         }
  1393.  
  1394.         /**
  1395.         * Title for otherSlice.<br>
  1396.         * Default value: Other
  1397.         *
  1398.         * @param value String
  1399.         */
  1400.         public function setText($value) {
  1401.             $this->text = $this->setStringProperty($this->text, $value);
  1402.         }
  1403.  
  1404.         /**
  1405.         * Value (value or percentage) for Otherslice grouping.
  1406.         *
  1407.         * @return double 
  1408.         */
  1409.         public function getValue() {
  1410.             return $this->aValue;
  1411.         }
  1412.  
  1413.         /**
  1414.         * Value (value or percentage) for Otherslice grouping.
  1415.         *
  1416.         * @param value double
  1417.         */
  1418.         public function setValue($value) {
  1419.             $this->aValue = $this->setDoubleProperty($this->aValue, $value);
  1420.         }
  1421.  
  1422.         /**
  1423.         * Either value or percentage to group the 'other' Pie slice.
  1424.         *
  1425.         *
  1426.         * @return PieOtherStyles 
  1427.         */
  1428.         public function getStyle() {
  1429.             return $this->style;
  1430.         }
  1431.  
  1432.         /**
  1433.         * Sets either value or percentage to group the 'other' Pie slice.
  1434.         *
  1435.         *
  1436.         * @param value PieOtherStyles
  1437.         */
  1438.         public function setStyle($value) {
  1439.             if ($this->style != $value) {
  1440.                 $this->style = $value;
  1441.                 $this->invalidate();
  1442.             }
  1443.         }
  1444.      }
  1445.  
  1446.      /**
  1447.      *
  1448.      * <p>Title: PieShadow class</p>
  1449.      *
  1450.      * <p>Description: Pie series uses this class in its Pie.Shadow.</p>
  1451.      *
  1452.      * <p>Copyright (c) 2005-2007 by Steema Software SL. All Rights Reserved.</p>
  1453.      *
  1454.      * <p>Company: Steema Software SL</p>
  1455.      *
  1456.      * @see Pie#getShadow
  1457.      */
  1458.      class PieShadow extends Shadow {
  1459.  
  1460.         public function PieShadow($c) {
  1461.             parent::Shadow($c);
  1462.  
  1463.             $tmpColor = new Color(120,120,120);  // DARK_GRAY
  1464.             $this->bBrush->setDefaultColor($tmpColor);
  1465.             $this->setDefaultVisible(false);
  1466.             $this->setDefaultSize(20);
  1467.         }
  1468.      }
  1469.  
  1470.      /**
  1471.      *
  1472.      * <p>Title: ExplodedSliceList class</p>
  1473.      *
  1474.      * <p>Description: List to hold percents of exploding effect, one per each
  1475.      * Pie slice.</p>
  1476.      *
  1477.      * <p>Copyright (c) 2005-2007 by Steema Software SL. All Rights Reserved.</p>
  1478.      *
  1479.      * <p>Company: Steema Software SL</p>
  1480.      *
  1481.      */
  1482.     /* class ExplodedSliceList extends ArrayObject {
  1483.  
  1484.         public function ExplodedSliceList($capacity) {
  1485.             // TODO remove ? parent::ExplodedSliceList($capacity);
  1486.         }
  1487.  
  1488.         public function getSlice($index) {
  1489.             if ($index < sizeof($this)) {
  1490.                 return ((int)parent::get($index));
  1491.             } else {
  1492.                 return 0;
  1493.             }
  1494.         }
  1495.  
  1496.         public function setSlice($index, $value) {
  1497.             while (sizeof($this) <= $index) {
  1498.                 $this->add(new Integer(0));
  1499.             }
  1500.             $this->set($index, new Integer($value));
  1501.         }
  1502.  
  1503.         private function exchange($a, $b) {
  1504.              $s = $this->getSlice($a);
  1505.             $this->setSlice($a, $this->getSlice($b));
  1506.             $this->setSlice($b, $s);
  1507.         }
  1508.      }
  1509.       */
  1510.     class CompareSlice implements Comparator {
  1511.         public function compare($a, $b) {
  1512.             $totalAngle = 2.0 * M_PI * $this->angleSize / 360.0;
  1513.             $tmpA = $this->getAngleSlice($this->sortedSlice[$a], $totalAngle);
  1514.             $tmpB = $this->getAngleSlice($this->sortedSlice[$b], $totalAngle);
  1515.             if ($tmpA < $tmpB) {
  1516.                 return -1;
  1517.             } else if ($tmpA > $tmpB) {
  1518.                 return 1;
  1519.             } else {
  1520.                 return 0;
  1521.             }
  1522.         }
  1523.     }
  1524.  
  1525.     /**
  1526.      *
  1527.      * <p>Title: SliceValueList class</p>
  1528.      *
  1529.      * <p>Description: List to hold percents of height for each Pie slice.</p>
  1530.      *
  1531.      * <p>Copyright (c) 2005-2007 by Steema Software SL. All Rights Reserved.</p>
  1532.      *
  1533.      * <p>Company: Steema Software SL</p>
  1534.      *
  1535.      */
  1536.     final class SliceValueList extends ArrayObject {
  1537.         public $OwnerSeries;
  1538.  
  1539.         public function getSlice($index) {
  1540.             if ($index < sizeof($this)) {
  1541.                 return ((int)parent::offsetGet($index));
  1542.             } else {
  1543.                 return 0;
  1544.             }
  1545.         }
  1546.  
  1547.         public function setSlice($index, $value) {
  1548.             while ($index >= sizeof($this)) {
  1549.  
  1550.                 parent::append(0);
  1551.             }
  1552.  
  1553.             if ( ((int)parent::offsetGet($index)) != $value) {
  1554.                 parent::offsetSet($index, $value);
  1555.                 $this->OwnerSeries->repaint();
  1556.             }
  1557.         }
  1558.  
  1559.         private function exchange($a, $b) {
  1560.             $s = $this->getSlice($a);
  1561.             $this->setSlice($a, $this->getSlice($b));
  1562.             $this->setSlice($b, $s);
  1563.         }
  1564.     }
  1565.  
  1566.     /**
  1567.      *
  1568.      * <p>Title: ExplodedSliceList class</p>
  1569.      *
  1570.      * <p>Description: List to hold percents of exploding effect, one per each
  1571.      * Pie slice.</p>
  1572.      *
  1573.      * <p>Copyright (c) 2005-2007 by Steema Software SL. All Rights Reserved.</p>
  1574.      *
  1575.      * <p>Company: Steema Software SL</p>
  1576.      *
  1577.      */
  1578.     final class ExplodedSliceList extends ArrayObject {
  1579.         /**
  1580.         * The class constructor.
  1581.         */
  1582.         public function ExplodedSliceList() {
  1583.             parent::__construct();
  1584.         }
  1585.  
  1586.         public function getSlice($index) {
  1587.             if ($index < sizeof($this)) {
  1588.                 return ((int)parent::offsetGet($index));
  1589.             } else {
  1590.                 return 0;
  1591.             }
  1592.         }
  1593.  
  1594.         public function setSlice($index, $value) {
  1595.             while (sizeof($this) <= $index) {
  1596.                 parent::append(0);
  1597.             }
  1598.             parent::offsetSet($index, $value);
  1599.         }
  1600.  
  1601.         private function exchange($a, $b) {
  1602.             $s = $this->getSlice($a);
  1603.             $this->setSlice($a, $this->getSlice($b));
  1604.             $this->setSlice($b, $s);
  1605.         }
  1606.     }
  1607. ?>

Documentation generated on Wed, 16 Jun 2010 12:07:19 +0200 by phpDocumentor 1.4.1